<!doctype html>



  


<html class="theme-next mist use-motion">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/vendors/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/vendors/font-awesome/css/font-awesome.min.css?v=4.4.0" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.0.1" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="模块使用," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.0.1" />






<meta name="description" content="pip更改国内安装源，升级、使用命令及离线使用方法">
<meta property="og:type" content="article">
<meta property="og:title" content="pip 使用全解析">
<meta property="og:url" content="http://rainy008.github.io/2017/06/05/pip 使用全解析/index.html">
<meta property="og:site_name" content="Rainy008">
<meta property="og:description" content="pip更改国内安装源，升级、使用命令及离线使用方法">
<meta property="og:image" content="http://rainy008.github.io/2017/06/05/pip 使用全解析/pip命令.jpg">
<meta property="og:updated_time" content="2017-06-05T14:03:22.255Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="pip 使用全解析">
<meta name="twitter:description" content="pip更改国内安装源，升级、使用命令及离线使用方法">
<meta name="twitter:image" content="http://rainy008.github.io/2017/06/05/pip 使用全解析/pip命令.jpg">



<script type="text/javascript" id="hexo.configuration">
  var NexT = window.NexT || {};
  var CONFIG = {
    scheme: 'Mist',
    sidebar: {"position":"left","display":"post"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: 0,
      author: '博主'
    }
  };
</script>

  <title> pip 使用全解析 | Rainy008 </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  










  
  
    
  

  <div class="container one-collumn sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta ">
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">Rainy008</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">重拾梦想  茕茕前行</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      

      
    </ul>
  

  
</nav>

 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                pip 使用全解析
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">发表于</span>
            <time itemprop="dateCreated" datetime="2017-06-05T21:43:43+08:00" content="2017-06-05">
              2017-06-05
            </time>
          </span>

          
            <span class="post-category" >
              &nbsp; | &nbsp;
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
              
                <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
                  <a href="/categories/Python/" itemprop="url" rel="index">
                    <span itemprop="name">Python</span>
                  </a>
                </span>

                
                

              
            </span>
          

          
            
              <span class="post-comments-count">
                &nbsp; | &nbsp;
                <a href="/2017/06/05/pip 使用全解析/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count ds-thread-count" data-thread-key="2017/06/05/pip 使用全解析/" itemprop="commentsCount"></span>
                </a>
              </span>
            
          

          

          
          

          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>python3.4以后自带pip，无需再安装。</p>
<h1 id="1、使用国内安装源"><a href="#1、使用国内安装源" class="headerlink" title="1、使用国内安装源"></a>1、使用国内安装源</h1><p>​    用pip安装依赖包时默认访问<code>https://pypi.Python.org/simple/</code>，但是经常出现不稳定以及访问速度非常慢的情况，国内厂商提供的pipy镜像速度快、稳定，目前可用的有：</p>
<p>​    清华：<a href="https://pypi.tuna.tsinghua.edu.cn/simple" target="_blank" rel="external">https://pypi.tuna.tsinghua.edu.cn/simple</a></p>
<p>​    阿里云：<a href="http://mirrors.aliyun.com/pypi/simple/" target="_blank" rel="external">http://mirrors.aliyun.com/pypi/simple/</a></p>
<p>​    中国科技大学 <a href="https://pypi.mirrors.ustc.edu.cn/simple/" target="_blank" rel="external">https://pypi.mirrors.ustc.edu.cn/simple/</a></p>
<p>​    华中理工大学：<a href="http://pypi.hustunique.com/" target="_blank" rel="external">http://pypi.hustunique.com/</a></p>
<p>​    山东理工大学：<a href="http://pypi.sdutlinux.org/" target="_blank" rel="external">http://pypi.sdutlinux.org/</a> </p>
<p>​    豆瓣：<a href="http://pypi.douban.com/simple/" target="_blank" rel="external">http://pypi.douban.com/simple/</a></p>
<p><strong>创建%HOMEPATH%\pip\pip.ini文件来配置国内安装源。</strong>例如：</p>
<p>​    在C:\Users\R\文件夹下创建pip文件夹，然后在其中创建pip.ini文件进行配置，最后路径为C:\Users\R\pip\pip.ini。</p>
<p>​    pip.ini文件内容如下（使用科技大的镜像）：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">[global]</div><div class="line">index-url = https://pypi.mirrors.ustc.edu.cn/simple/</div><div class="line">trusted-host=pypi.mirrors.ustc.edu.cn</div></pre></td></tr></table></figure>
<h1 id="2、pip升级"><a href="#2、pip升级" class="headerlink" title="2、pip升级"></a>2、pip升级</h1><p>​    Windows下pip升级命令：</p>
<p>​     <code>python -m  pip install --upgrade pip</code> 或 <code>python -m pip install -u pip</code></p>
<h1 id="3、pip命令"><a href="#3、pip命令" class="headerlink" title="3、pip命令"></a>3、pip命令</h1><p><img src="/2017/06/05/pip 使用全解析/pip命令.jpg" alt="pip命令"></p>
<p>​    <strong>对于不熟悉的pip命令，要善用–help，例如：</strong></p>
<p>​    <strong><code>pip install -h</code>或者<code>pip install --help</code></strong></p>
<h1 id="4、批量升级包"><a href="#4、批量升级包" class="headerlink" title="4、批量升级包"></a>4、批量升级包</h1><p>​    用循环实现批量升级包（注意–upgrade后面的空格）</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">import</span> pip</div><div class="line"><span class="keyword">from</span> subprocess <span class="keyword">import</span> call</div><div class="line"></div><div class="line"><span class="keyword">for</span> dist <span class="keyword">in</span> pip.get_installed_distributions():</div><div class="line">    print(<span class="string">"Package Name: "</span>+ dist.project_name)</div><div class="line">    call(<span class="string">"pip install --upgrade "</span> + dist.project_name, shell=<span class="keyword">True</span>)</div></pre></td></tr></table></figure>
<p>​    另外的也可以使用 <a href="https://github.com/jgonggrijp/pip-review" target="_blank" rel="external">pip-review</a> 模块，不过还有安装（不推荐）</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">pip install pip-review</div><div class="line">pip-review --local --interactive</div></pre></td></tr></table></figure>
<h1 id="5、pip离线使用"><a href="#5、pip离线使用" class="headerlink" title="5、pip离线使用"></a>5、pip离线使用</h1><pre><code>当不能联网而使用python时，你会遇到各种关于安装、使用包的坑，你会疑惑、沮丧、痛苦，甚至绝望……
</code></pre><p>​    直到有一天，你突然知道pip原来可以离线安装包……</p>
<p>​    你发现原来大神就是大神，创造python的大神们早已为你准备好了一切，只是你自己一直徘徊在单机的苦难中，没有找到通往“便捷”的天堂之道……</p>
<p>​    你又重拾起沿着python之路一往无前的勇气，向着人机自由交流的光明未来继续前行……</p>
<p>​    以上就是我近半年来的经历！也是我要好好总结pip使用的原因！</p>
<p>​    首先，在一台能联网的电脑上更新要下载的包</p>
<p>​    然后，在你喜欢的地方创建一个文件夹用来存放要下载的包，例如 <code>D:\packages\</code></p>
<p>​    接着，运行命令：<code>pip freeze &gt; D:\requirements.txt  (或者 req.txt 随你喜欢的文件名)</code>,你安装的包的名称、版本号都会被导入D盘requirems.txt文件内，内容如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div></pre></td><td class="code"><pre><div class="line">beautifulsoup4==4.6.0</div><div class="line">certifi==2017.4.17</div><div class="line">chardet==3.0.3</div><div class="line">cobble==0.1.3</div><div class="line">Cython==0.25.2</div><div class="line">docx==0.2.4</div><div class="line">idna==2.5</div><div class="line">lxml==3.8.0</div><div class="line">mammoth==1.4.0</div><div class="line">olefile==0.44</div><div class="line">Pillow==4.1.1</div><div class="line">pytesseract==0.1.7</div><div class="line">python-docx==0.8.6</div><div class="line">requests==2.17.3</div><div class="line">selenium==3.4.3</div><div class="line">tesseract==0.1.3</div><div class="line">urllib3==1.21.1</div><div class="line">xlrd==1.0.0</div></pre></td></tr></table></figure>
<p>​    之后，运行命令<code>pip download -d d:\packages -r d:\requirements.txt</code>，下载上述所列包。</p>
<p>​    最后，将D:\packages文件夹中的包拷贝到不能联网的电脑上，运行命令<code>pip install install --no-index --find-links=d:\packages -r requirements.txt</code>，requirements.txt文件中所列的包就安装到未联网的电脑上了</p>
<p>​    从此，再不用痛苦包的问题了！！！</p>
<p>关于 download 和 install 命令的具体用法，现用现help :-)</p>
<h1 id="参考"><a href="#参考" class="headerlink" title="参考"></a>参考</h1><ul>
<li><a href="http://stackoverflow.com/questions/7225900/how-to-pip-install-packages-according-to-requirements-txt-from-a-local-directory" target="_blank" rel="external">http://stackoverflow.com/questions/7225900/how-to-pip-install-packages-according-to-requirements-txt-from-a-local-directory</a></li>
</ul>
<ul>
<li><a href="http://www.lfd.uci.edu/~gohlke/pythonlibs/" target="_blank" rel="external">推荐-离线包下载Unofficial Windows Binaries for Python Extension Packages</a></li>
<li><a href="https://pip.pypa.io/en/latest/installing/#install-pip" target="_blank" rel="external">pip文档</a></li>
<li><a href="http://blog.csdn.net/xyqzki/article/details/38414433" target="_blank" rel="external">python安装第三方的包</a></li>
<li><a href="http://jude90.github.io/2015/09/30/pip-from-dir.html" target="_blank" rel="external">如何制作一个 pip 离线安装环境</a></li>
<li><a href="https://taizilongxu.gitbooks.io/stackoverflow-about-python/content/8/README.html" target="_blank" rel="external">推荐-怎么在windows下安装pip?</a></li>
<li><a href="http://me.iblogc.com/2015/01/01/pip%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4/" target="_blank" rel="external">推荐-pip常用命令</a></li>
</ul>

      
    </div>

    <div>
      
        
      
    </div>

    <div>
      
        
  <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
    <div>坚持原创技术分享，您的支持将鼓励我继续创作！</div>
    <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
      <span>赏</span>
    </button>
    <div id="QR" style="display: none;">
      
        <div id="wechat" style="display: inline-block">
          <img id="wechat_qr" src="/path/to/wechat-reward-image" alt="Rainy008 WeChat Pay"/>
          <p>微信打赏</p>
        </div>
      
      
        <div id="alipay" style="display: inline-block">
          <img id="alipay_qr" src="/path/to/alipay-reward-image" alt="Rainy008 Alipay"/>
          <p>支付宝打赏</p>
        </div>
      
    </div>
  </div>


      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/模块使用/" rel="tag">#模块使用</a>
          
        </div>
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/05/31/splite 避免插入重复数据/" rel="next" title="splite避免插入重复数据">
                <i class="fa fa-chevron-left"></i> splite避免插入重复数据
              </a>
            
          </div>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/06/08/(转载) pycharm快捷键及一些常用设置/" rel="prev" title="(转载)pycharm快捷键及一些常用设置">
                (转载)pycharm快捷键及一些常用设置 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
      <div class="ds-thread" data-thread-key="2017/06/05/pip 使用全解析/"
           data-title="pip 使用全解析" data-url="http://rainy008.github.io/2017/06/05/pip 使用全解析/">
      </div>
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel ">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/avatar.gif"
               alt="Rainy008" />
          <p class="site-author-name" itemprop="name">Rainy008</p>
          <p class="site-description motion-element" itemprop="description">留下记忆足迹，记录所学所想</p>
        </div>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">8</span>
              <span class="site-state-item-name">日志</span>
            </a>
          </div>

          
            <div class="site-state-item site-state-categories">
              <a href="/categories">
                <span class="site-state-item-count">4</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            <div class="site-state-item site-state-tags">
              <a href="/tags">
                <span class="site-state-item-count">5</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
        </div>

        
        

        
        

      </section>

      
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">
            
              
            
            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#1、使用国内安装源"><span class="nav-text">1、使用国内安装源</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#2、pip升级"><span class="nav-text">2、pip升级</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#3、pip命令"><span class="nav-text">3、pip命令</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#4、批量升级包"><span class="nav-text">4、批量升级包</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#5、pip离线使用"><span class="nav-text">5、pip离线使用</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#参考"><span class="nav-text">参考</span></a></li></ol></div>
            
          </div>
        </section>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Rainy008</span>
</div>

<div class="powered-by">
  由 <a class="theme-link" href="http://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Mist
  </a>
</div>

        

        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  



  
  <script type="text/javascript" src="/vendors/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/vendors/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/vendors/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/vendors/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/vendors/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/vendors/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.0.1"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.0.1"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.0.1"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.0.1"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.0.1"></script>



  

  
    
  

  <script type="text/javascript">
    var duoshuoQuery = {short_name:"rainy008"};
    (function() {
      var ds = document.createElement('script');
      ds.type = 'text/javascript';ds.async = true;
      ds.id = 'duoshuo-script';
      ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
      ds.charset = 'UTF-8';
      (document.getElementsByTagName('head')[0]
      || document.getElementsByTagName('body')[0]).appendChild(ds);
    })();
  </script>

  
    
  





  
  
  

  

  

</body>
</html>
